<template>
  <div class="">
    <ul>
      <h1>未完成</h1>
      <li
        v-for="(item, index) in $store.state.list"
        :key="index"
        v-show="item.status == 0"
      >
        <input type="checkbox" v-model="item.status" />
        <input
          type="text"
          v-model="item.title"
          v-if="flag == index"
          @blur="flag = -1"
          id="box"
          @change="changes"
        />
        <span @dblclick="edit(index)" v-else>{{ item.title }}</span>
        <span @click="remove(index)">x</span>
      </li>
    </ul>
    <ul>
      <h1>已完成</h1>
      <li
        v-for="(item, index) in $store.state.list"
        :key="index"
        v-show="item.status == 1"
      >
        <input type="checkbox" v-model="item.status" />
        <span>{{ item.title }}</span>
        <span @click="remove(index)">x</span>
      </li>
    </ul>
  </div>
</template>

<script>
export default {
  data() {
    return {
      flag: -1,
    };
  },
  created() {},
  methods: {
    remove(index) {
      this.$store.commit("remove", index);
    },
    edit(index) {
      this.flag = index;
      //   console.log(this.$refs.box);
      this.$nextTick(() => {
        // this.$refs.box.focus();
        document.getElementById("box").focus();
      });
      //nexttick会把代码变成dom更新之后执行
    },
    changes() {
      this.$store.commit("changes");
    },
  },
  components: {},
};
</script>

<style lang="scss"></style>
